package com.ctrip.demo.leetcode;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.locks.ReadWriteLock;

/**
 * @author xs.wu
 */
public class LeetCode1 {


    public static int[] twoSum(int[] nums, int target) {

        Map<Integer,Integer> map = new TreeMap<Integer, Integer>();

        for( int i = 0; i < nums.length; i ++) {
            map.put((target - nums[i]), i);
        }

        for( int i = 0; i < nums.length; i ++) {
            if(map.get(nums[i]) != null && map.get(nums[i]) != i) {
                return new int[]{i, map.get(nums[i])};
            }
        }

        return null;

    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(twoSum(new int[]{3,2,4}, 6)));
    }


}
